#!/bin/bash
#Program
#	User input a filename , program will check the following:
# 	1).exits? 2).file/directory? 3).file permissions
#History
#	2013/6/29	Niuliguo	First release
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

#让用户输入文件名，并且判断用户是否真的有输入字符串
echo -e "please input a filename , I will check the filename's type and permissions.\n"
read -p "Input a filename : " filename
test -z $filename && echo "you must input a filename." && exit 0

test ! -e $filename && echo "The filename '$filename' DO NOT exist" && exit 0

test -f $filename && filetype="regular file"
test -d $filename && filetype="directory"

test -r $filename && perm="readable"
test -w $filename && perm="$perm writable"
test -x $filename && perm="$perm executalbe"

echo "The filename : $filename is a $filetype"
echo "And the permissions are : $perm"

